const KPITypeMap = {
  trafficIn: 1, //进客流;
  trafficOut: 2, //出客流客流;
  trafficFitting: 3, //试衣量;
  pass: 4, //过客量
  inStoreRate:5,//进店率
  batchIn: 6,//批量进
  batchOut: 7,//批量出,
  dressingRate: 8,//体验率

  conversation: 6, //成交率
  amount: 4, //销售额
  
}

const KPINameMap = {
  trafficIn: 'in', //进客流;
  trafficOut: 'out', //出客流客流;
  trafficFitting: 'fitting', //试衣量;
  pass: 'passing', //过客量
  inStoreRate:'inStoreRate',//进店率
  batchIn:'batchIn',//批量进
  batchOut:'batchOut',//批量出,
  dressingRate:'dressingRate',//体验率
}

const KPITypeToKey = function (type) {
  switch (type) {
    case KPITypeMap.trafficIn:
      return KPINameMap.trafficIn;
    case KPITypeMap.trafficOut:
      return KPINameMap.trafficOut
    case KPITypeMap.trafficFitting:
      return KPINameMap.trafficFitting
    case KPITypeMap.dressingRate:
      return KPINameMap.dressingRate;
    case KPITypeMap.inStoreRate:
      return KPINameMap.inStoreRate;
    case KPITypeMap.pass:
      return KPINameMap.pass;
    case KPITypeMap.batchIn:
      return KPINameMap.batchIn;
    case KPITypeMap.batchOut:
      return KPINameMap.batchOut;
  }
  return '';
}

const KPITypeToName = function (type) {
  switch (type) {
    case KPITypeMap.trafficIn:
      return '进客流';
    case KPITypeMap.trafficOut:
      return '出客流';
    case KPITypeMap.trafficFitting:
      return '体验数';
    case KPITypeMap.dressingRate:
      return '体验率';
    case KPITypeMap.inStoreRate:
      return '进店率';
    case KPITypeMap.pass:
      return '过客量';
    case KPITypeMap.batchIn:
      return '进批次';
    case KPITypeMap.batchOut:
      return '出批次';
  }
}
const KPIValueFormat = function (value,type) {
  switch (type) {
    case KPITypeMap.inStoreRate:
      return (value * 100).toFixed(2) + '%';
    case KPITypeMap.dressingRate:
      return (value*100).toFixed(2) + '%';
  }
  return value;
}

/**
 * KPI
 */
class KPI {
  constructor(type = KPITypeMap.trafficIn, value = 0) {
    this.type = type;
    this.value = value;
    this.key = KPITypeToKey(type)
  }
  //前端自动根据类型来格式化
  
  
  set type(type) {
    this._type = type;
    this.name = KPITypeToName(this._type);
    this.key = KPITypeToKey(this._type);
  }
  get type() {
    return this._type;
  }
  set value(value){
    this._value = KPIValueFormat(value,this._type);
  }
  get value()
  {
    return this._value;
  }
  
  


}
module.exports = {
  KPITypeMap: KPITypeMap,
  KPI: KPI,
  KPINameMap: KPINameMap,
  KPIValueFormat: KPIValueFormat,
  KPITypeToName: KPITypeToName,
  KPITypeToKey: KPITypeToKey

}